<template>
	<view>
		<block v-for="(item,index) in formData" :key="index">
			<cardList :showType='cardShowTypeObj' :itemData='item' source='browsingHistory'
				@clearItem="handleClearItem"></cardList>
		</block>
		<view class="main dis" style="z-index: 9999;height: 80vh;" v-if="formData.length == 0">
			<view style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
				<image src="https://hosue-omo.oss-cn-shenzhen.aliyuncs.com/assets/noData.png" mode="aspectFit" style="width: 200rpx;height: 200rpx;"></image>
				<text>暂无数据</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		reactive,
		ref,
		onMounted
	} from 'vue'
	import {
		userViews,
		viewsRemove
	} from './js/api.js'
	import {
		onReachBottom
	} from '@dcloudio/uni-app'
	import http from '@/uitls/http.js'
	const cardShowTypeObj = reactive({
		infolabel: true,
		address: true,
		time: false,
		label: true
	})
	const paramsData = reactive({
		pageNum: 1,
		pageSize: 10
	})
	const formData = ref([])
	const isReach = ref(true)
	const getUserViews = async () => {
		let res = await userViews(paramsData)
		console.log('请求结束----', res.data.data.list)
		let list = res.data.data.list
		if (paramsData.pageNum == 1) {
			formData.value = list
		} else {
			formData.value = formData.value.concat(list)
		}
		if (list.length < 10) isReach.value = false
	}
	const viewsRemoveData = async (id) => {

		let res = await viewsRemove(id)
		console.log(res)
		if (res.data.code < 0) {
			http.isMssage(res.data.message)
		}else{
			let list = formData.value
			let arryList = list.filter(item => item.id != id)
			console.log(arryList)
			formData.value = arryList
		}
		
		
		console.log('id===,', id)
	}
	const handleClearItem = (id) => {
		console.log('你点击了删除，，', id)
		uni.showModal({
			title: '提示',
			content: '确定删除嘛～？',
			success: function(res) {
				if (res.confirm) {
					viewsRemoveData(id)
				} else if (res.cancel) {
					console.log('用户取消');
				}
			}
		});

	}
	onReachBottom(() => {
		// console.log('上拉触底')
		if (!isReach.value) return
		paramsData.pageNum++
		getUserViews()
	})

	onMounted(() => {
		getUserViews()
		console.log('请求开始----')
	})
</script>
<style>
	page {
		background: #F6F6F6 !important;
	}
</style>
<style lang="less">

</style>